package com.ruoyi.web.controller.ltd_web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.ltd_web.domain.LtdNews;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ltd_web.domain.LtdNotice;
import com.ruoyi.ltd_web.service.ILtdNoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 公司公告信息Controller
 *
 * @author ruoyi
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/system/ltd_notice")
public class LtdNoticeController extends BaseController
{
    @Autowired
    private ILtdNoticeService ltdNoticeService;

    /**
     * 查询公司公告信息列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(LtdNotice ltdNotice)
    {
        startPage();
        List<LtdNotice> list = ltdNoticeService.selectLtdNoticeList(ltdNotice);
        return getDataTable(list);
    }

    /**
     * 导出公司公告信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:notice:export')")
    @Log(title = "公司公告信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LtdNotice ltdNotice)
    {
        List<LtdNotice> list = ltdNoticeService.selectLtdNoticeList(ltdNotice);
        ExcelUtil<LtdNotice> util = new ExcelUtil<LtdNotice>(LtdNotice.class);
        util.exportExcel(response, list, "公司公告信息数据");
    }

    /**
     * 获取公司公告信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ltdNoticeService.selectLtdNoticeById(id));
    }

    /**
     * 新增公司公告信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "公司公告信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LtdNotice ltdNotice)
    {
        return toAjax(ltdNoticeService.insertLtdNotice(ltdNotice));
    }

    /**
     * 修改公司公告信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "公司公告信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LtdNotice ltdNotice)
    {
        return toAjax(ltdNoticeService.updateLtdNotice(ltdNotice));
    }

    /**
     * 删除公司公告信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "公司公告信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ltdNoticeService.deleteLtdNoticeByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "公司公告--状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody LtdNotice ltdNotice)
    {
        return toAjax(ltdNoticeService.updateLtdNotice(ltdNotice));
    }

    /**
     * 上传文件
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "公司公告--上传文件", businessType = BusinessType.UPDATE)
    @PostMapping("/upload_pdf/")
    public AjaxResult upload_pdf(@RequestParam("file") MultipartFile file){

        return ltdNoticeService.upload_pdf(file);
    }

}
